<template>
<div>
    <el-table
      :data="tableData"
      border
      style="width: 100%">
      <el-table-column
        prop="aid"
        label="编号"
        width="180">
      </el-table-column>
      <el-table-column
        prop="name"
        label="图书名"
        width="180">
      </el-table-column>
      <el-table-column
        prop="price"
        label="单价">
      </el-table-column>
      <el-table-column
        prop="start"
        label="开始时间">
      </el-table-column>
      <el-table-column
        prop="end"
        label="结束时间">
      </el-table-column>
      <el-table-column
        prop="nums"
        label="数量">
      </el-table-column>
      <el-table-column label="状态">
        <template slot-scope="scope">
          <span v-if="scope.row.status == 0">未开始</span>
          <span v-if="scope.row.status == 1">进行中</span>
          <span v-if="scope.row.status == 2">已结束</span>
        </template>
      </el-table-column>
      <el-table-column label="时间">
        <template slot-scope="scope">
         距离开始:<CountDown :end-time="scope.row.start"></CountDown>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        label="操作"
        width="100">
        <template slot-scope="scope">
          <el-button v-if="scope.row.status==0"  @click="dialogFormVisible=true;activityupd=scope.row" type="primary"
                     icon="el-icon-edit" size="mini">修改</el-button>
          <el-button v-if="scope.row.status==1" disabled @click="dialogFormVisible=true;activityupd=scope.row" type="primary"
                     icon="el-icon-edit" size="mini">修改</el-button>
          <el-button v-if="scope.row.status==2"  @click="dialogFormVisible=true;activityupd=scope.row" type="primary"
                     icon="el-icon-edit" size="mini">修改</el-button>

        </template>

      </el-table-column>
    </el-table>
    <el-dialog title="收货地址" :visible.sync="dialogFormVisible">
      <el-form :model="activityupd">
        <el-form-item label="价格" :label-width="formLabelWidth">
          <el-input v-model="activityupd.price" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="开始时间" :label-width="formLabelWidth">
        <el-date-picker
          v-model="activityupd.start"  value-format="yyyy-MM-dd HH:mm:ss"
          type="datetime" style="width: 610px"
          placeholder="选择日期开始时间">
        </el-date-picker>
        </el-form-item>
        <el-form-item label="结束时间" :label-width="formLabelWidth">
          <el-date-picker
            v-model="activityupd.end"  value-format="yyyy-MM-dd HH:mm:ss"
            type="datetime" style="width: 610px"
            placeholder="选择日期开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="数量" :label-width="formLabelWidth">
          <el-input v-model="activityupd.nums" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogFormVisible = false,activityupdate()">确 定</el-button>
      </div>
    </el-dialog>


</div>
</template>

<script>
import CountDown from "@/components/CountDown";

export default {
  name: "Activity",
  components: {CountDown},
  data(){
    return{
   tableData: [],
      dialogFormVisible:false,
      activityupd:{},
      formLabelWidth: '120px'
    }
  },
  comments:{CountDown},
  created() {
this.find()
  },
  methods:{
   find(){
     this.$http.post('backservice/acivity/find').then(data=>{
       this.tableData=data
     })
   },
  activityupdate(){
     this.$http.post('backservice/acivity/update',this.activityupd).then(data=>{
       if (data>0){
         this.$message({
           message: '恭喜你，修改成功',
           type: 'success'
         });
         this.find()
       }else {
         this.$message.error('错了哦，这是一条错误消息');
       }
     })

  }
  }
}
</script>

<style scoped>

</style>
